package xyz.weizhi.rjwm.common;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @Author milian
 * @Date 2021/9/25 0025 9:29
 */
@Component
public class MyMateObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        //设置公共字段
        metaObject.setValue("createTime", LocalDateTime.now());
        metaObject.setValue("createUser",baseContext.getThreadLocal());
        metaObject.setValue("updateUser",baseContext.getThreadLocal());
        metaObject.setValue("updateTime", LocalDateTime.now());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        metaObject.setValue("updateTime", LocalDateTime.now());
        metaObject.setValue("updateUser",baseContext.getThreadLocal());
    }
}
